﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Cosmetic.DataAccess;
using Cosmetic.DataEntity;
using System.Configuration;
using System.Data.Linq.SqlClient;
using System.Data.SqlClient;
using System.Data;

namespace Cosmetic.Logic
{
    public class PriceSelectClass
    {
        /// <summary>
        /// 查找所有的价格。
        /// </summary>
        /// <returns></returns>
        public static DataSet GetAllProduct()
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "select * from dbo.PriceSelect order by Other asc";

                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds;
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 新增价格
        /// </summary>
        /// <returns></returns>
        public static void InsertPriceGroup(string id,string priceF,string priceS,int indexs)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "INSERT INTO [dbo].[PriceSelect]  ([ID] ,[priceF]  ,[priceS] ,[Other])  VALUES ('" + id + "' ,'" + priceF + "' ,'" + priceS + "' ," + indexs + ")";
                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="priceF"></param>
        /// <param name="priceS"></param>
        /// <param name="indexs"></param>
        public static void UpdatePriceGroup(string ID ,string priceF, string priceS, int indexs)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "UPDATE [dbo].[PriceSelect] SET [priceF] ='" + priceF + "'  ,[priceS] ='" + priceS + "'  ,[Other] = " + indexs + "  WHERE [ID] ='" + ID + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        public static void DeletePriceGroup(string id)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "delete dbo.PriceSelect where ID = '" + id + "' ";
                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }
    }//end class
}
